<?php

class Core_Backend_Component_Website_View_Block_Create extends Core_Backend_Share_View_Form {

    public function __construct() {
        parent::__construct();
        $this->setTemplatePath('edit');
    }

    protected function buildNavigation($navigation) {
        $navigation->addLabel($this->__f('website.title.block_create', $this->getArea()->getName(), $this->getModule()->getTitle()));
        parent::buildNavigation($navigation);
    }

    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('website/block/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.apply'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(NULL, 'apply') . "')");
        $group->addButton($this->__('share.button.save'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(NULL, 'save') . "')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $model = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('module_form')
                ->addHiddenField('id', 'module[id]')
                ->addHiddenField('area_id', 'module[area_id]', $this->getArea()->getId())
                ->addHiddenField('module_id', 'module[module_id]', $this->getModule()->getId())
                ->addHiddenField('namespace', 'namespace', $this->getArea()->getNamespace())
                ->addHiddenField('modulename', 'modulename', $this->getModule()->getName());
        $form->addTextboxField($this->__('share.label.code'), 'code', 'module[code]', TRUE)->addRequiredRule();
        $form->addTextboxField($this->__('share.label.name'), 'name', 'module[name]', TRUE)->addRequiredRule();
        $form->addSelectField($this->__('share.label.enable'), 'enabled', 'module[enabled]', TRUE)
                ->bindData(Kd_Localize_Helper::getLanguageItems('status.boolean'))
                ->addRequiredRule();
        $form->addSelectField($this->__('share.label.title_enable'), 'title_enabled', 'module[parameters][title_enabled]', TRUE)
                ->bindData(Kd_Localize_Helper::getLanguageItems('status.boolean'))
                ->addRequiredRule();
        $form->addTextboxField($this->__('share.label.title'), 'title', 'module[parameters][title]');
        $form->addSelectField($this->__('website.label.share_block'), 'share_template_name', 'module[share_template_name]')
                ->setOption('--', '')
                ->bindData($this->getShareBlocks(), 'name', 'code');
        $form->addTextboxField($this->__('website.label.id_prefix'), 'id_prefix', 'module[parameters][id_prefix]');
        $form->addTextboxField($this->__('website.label.css_prefix'), 'css_prefix', 'module[parameters][css_prefix]');
        $this->getModuleConfig()->buildForm($form, is_null($model) ? array() : $model->getParameters(),$this->getTemplate());
        $form->addTextareaField($this->__('website.label.template_code'), 'template_script', 'module[template_script]')
                ->setStyle('height', 400);
        if ($model) {
            $form->bindData($model->getAllData());
            $form->bindData($model->getParameters());
        }
        parent::buildForm($form);
    }

}
